package mamikeji.liaowa.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import mamikeji.liaowa.R;

/**
 * Created by 廉冲-android开发 on 2017/5/17.
 */
public class ClockListTimetAdapter extends BaseAdapter {
    List<String> dayTimeList = new ArrayList<>();
    LayoutInflater inflater;
    Context context;
    private OnItemClickListener mOnItemClickListener;

    public ClockListTimetAdapter() {
    }

    public ClockListTimetAdapter(List<String> dayTimeList, Context context) {
        this.dayTimeList = dayTimeList;
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    public void setList(List<String> dayTimeList) {
        this.dayTimeList = dayTimeList;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return dayTimeList.size();
    }

    @Override
    public String getItem(int position) {
        return dayTimeList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_clock_list_time, null);
            viewHolder = new ViewHolder();

            viewHolder.textView_clock_item_time = (TextView) convertView.findViewById(R.id.textView_clock_item_time);
            viewHolder.imageView_clock_item_delete = (ImageView) convertView.findViewById(R.id.imageView_clock_item_delete);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.textView_clock_item_time.setText(dayTimeList.get(position));

        viewHolder.imageView_clock_item_delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mOnItemClickListener.onDeleteOnClick(position);
            }
        });
        return convertView;
    }

    public class ViewHolder {
        TextView textView_clock_item_time;
        ImageView imageView_clock_item_delete;
    }

    public interface OnItemClickListener {
        void onDeleteOnClick(int position);
    }

    public void setOnItemClickListener(OnItemClickListener mOnItemClickListener) {
        this.mOnItemClickListener = mOnItemClickListener;
    }
}
